package com.woniuxy02;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-08-29 14:23
 */
public class Test04 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] array = {1, 3, 45, 12, 5, 0, 0, 0};
        System.out.println("输入你要删除的元素");
        int num = sc.nextInt();
        int beginIndex = -1;
        int endIndex = -1;
        for (int i = 0; i < array.length; i++) {
            if (num == array[i]) {
                beginIndex = i;
                break;
            }
        }
        if(beginIndex == -1){
            System.out.println("不存在这个元素");
        }else{
            for (int i = 0; i < array.length; i++) {
                if (array[i] == 0) {
                    endIndex = i;
                    break;
                }
            }
            //移动元素
            for(int i=beginIndex;i<=endIndex-1;i++){
                array[i] = array[i+1];
            }
        }

        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+"\t");
        }
        System.out.println();

    }
}
